package com.taojiazheng.controller.user;

import com.taojiazheng.common.ResultResponse;
import com.taojiazheng.common.UpLoadFile;
import com.taojiazheng.common.annotations.VisitorAccessible;
import com.taojiazheng.service.user.UserService;
import com.taojiazheng.so.user.UserSo;
import com.taojiazheng.vo.user.UserVo;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.lang.reflect.Method;

/**
 * @author 赵成林
 * @date 2017/11/22 23:03
 */
//@CrossOrigin(origins = "*", maxAge = 3600)
@Controller
@RequestMapping(value = "user")
public class LoginController {
    private Logger logger = Logger.getLogger(LoginController.class);
    @Autowired
    private UserService userService;
    @Autowired
    private UpLoadFile upLoadFile;
    @ResponseBody
    @RequestMapping(value = "login",method = RequestMethod.POST)
    public ResultResponse<UserVo> login(@RequestBody UserSo userSo){
        logger.info("userName: "+userSo.getUserName()+"  "+"password: "+userSo.getPassword());
        UserVo userVo = userService.login(userSo);
        return new ResultResponse<UserVo>(userVo);
    }

//     测试文件上传
//    @VisitorAccessible
//    @ResponseBody
//    @RequestMapping(value = "test")
//    public String test(@RequestParam("file") MultipartFile multipartFile, String fileName, HttpServletRequest request){
//        upLoadFile.uploadFile(fileName,multipartFile,request);
//        return "success";
//    }
//
 }
